﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Pragma" content="no-cache">
<link rel="STYLESHEET" type="text/css" id="SkinStyleSheet">
<title>WebNoteEditor</title>
<style>
#Cam{
	border:2px #C0C0C0 solid
}
</style>
<script language="javascript" type="text/javascript" src="../script/windialog.js"></script>
<script language="javascript" type="text/javascript">

window.onload=function()
{
	
	var selSize=new EditorWindow._HTMLselect("selectSize",document);
	var targetOptions = new Array(
		new Array("", EditorWindow.lang_campreviewsize),
		new Array("320,240", "320px * 240px"), 
		new Array("640,480", "640px * 480px")
	);
	selSize.addOptions(targetOptions);

	
	document.getElementById("btnStart").value=EditorWindow.lang_camstart;
	document.getElementById("btnStart").onclick=__btnStart_onclick;
	document.getElementById("btnCapture").value=EditorWindow.lang_camcapture;
	document.getElementById("btnCapture").onclick=__btnCapture_onclick;
	
	document.getElementById("btnSetting").value=EditorWindow.lang_camsetting;
	document.getElementById("btnSetting").onclick=__btnSetting_onclick;
	document.getElementById("btnsetFormat").value=EditorWindow.lang_camsetformat;
	document.getElementById("btnsetFormat").onclick=__btnsetFormat_onclick;
	
	if (document.getElementById("Cam"))
	{
		document.getElementById("selectSize").onchange=__selectSize_onchange;
		__selectSize_onchange("320,240");
		selSize.focusOption("320,240");
	}
	else
	{
		document.getElementById("btnStart").disabled=true;
		document.getElementById("btnCapture").disabled=true;
	}
	AutoResizeDialogWindow();
}


window.beforeunload=function()
{
	try{
		if (document.getElementById("btnStart").getAttribute("start")=="true")
			Cam.Release();
	}
	catch(e)
	{}
}

function __selectSize_onchange(value)
{
	try{
		var width,height;
		if (value)
			this.value=value;
		if (this.value!="")
		{
			var tempStr=this.value.toString().split(",");
			width=tempStr[0];
			height=tempStr[1];
			document.getElementById("Cam").picWidth=parseInt(width);
			document.getElementById("Cam").picHeight=parseInt(height);
			document.getElementById("Cam").style.width=document.getElementById("Cam").picWidth+"px";
			document.getElementById("Cam").style.height=document.getElementById("Cam").picHeight+"px";
			
			if (document.getElementById("btnStart").getAttribute("start")=="true")
			{
				Cam.Release();
				Cam.Start();
			}

		}
	}
	catch(e)
	{
	}
	window.dialogWidth="100px";
	window.dialogHeight="800px";
	
	AutoResizeDialogWindow();
}

function __btnStart_onclick()
{
	var s;
	document.getElementById("btnStart").disabled=true;
	if (document.getElementById("btnStart").getAttribute("start")=="false")
	{
		s=Cam.Start();
		if (s==1)
		{
			document.getElementById("btnStart").setAttribute("start","true");
			document.getElementById("btnStart").value=EditorWindow.lang_camstop;
			document.getElementById("btnStart").disabled=false;
			document.getElementById("btnSetting").disabled=false;
			document.getElementById("btnCapture").disabled=false;
			document.getElementById("btnsetFormat").disabled=false;
			
		}
		else
		{
			if (s==2)
			{
				alert(EditorWindow.lang_cam_err_connection);
			}
			else
			{
				alert(Cam.errDescription);
			}
			document.getElementById("btnStart").disabled=true;
			document.getElementById("btnSetting").disabled=true;
			document.getElementById("btnCapture").disabled=true;
			document.getElementById("btnsetFormat").disabled=true;
		}
	}
	else
	{
		document.getElementById("btnStart").setAttribute("start","false");
		Cam.Release();
		document.getElementById("btnStart").value=EditorWindow.lang_camstart;
	}
	document.getElementById("btnStart").disabled=false;

}
function __btnCapture_onclick()
{
	document.getElementById("Cam").Capture();
	document.getElementById("btnCapture").disabled=true;
	document.getElementById("btnStart").setAttribute("start","false");
	document.getElementById("btnStart").value=EditorWindow.lang_camstart;
	document.getElementById("btnCapture").hasCapture=true;
}
function __btnSetting_onclick()
{
	Cam.setSource();
}

function __btnsetFormat_onclick()
{
	Cam.setFormat();
}

function __btnOk_onclick()
{
	var localfilePath,outFilePath
	
	if(document.getElementById("btnCapture").hasCapture)
	{
		try
		{
			if (EditorWindow.$WebNoteEx.SaveClipBoardImageToFile())
			{
				localfilePath=EditorWindow.$WebNoteEx.ClipBoardImagePath;

				if (EditorWindow.$config.capturescreenfileextname!="png")
				{
					outFilePath=localfilePath.replace(".png","."+EditorWindow.$config.capturescreenfileextname);
					if (EditorWindow.$WebNoteEx.Convert(localfilePath,outFilePath))
					{
						localfilePath=outFilePath;
					}
				}

				EditorWindow.pasteHTML("<img src='"+localfilePath+"'>");
				EditorWindow.PreviewAllLocalIMG();
			}
		}
		catch(e)
		{
		
		}
	}
	//EditorWindow.__paste();
	window.close();
}


function __btnCancel_onclick()
{
	window.close();
}
</script>
</head>
<body class="dialog">
<script language="javascript" type="text/javascript">dialogTitle("lang_capturefromcam")</script>
<script language="javascript" type="text/javascript">
	document.write("<OBJECT id=\"Cam\" classid=\"clsid:2A02E716-75A2-499B-9C46-D5E29927979E\"><div style=\"width:300px;padding:20px;background-color:#ffffee;border:1px #000000 dotted;text-align:center;color:red;font-weight:bold;\">"+EditorWindow.lang_cam_tips1+"</div></OBJECT>");
</script>

<div>
<select id="selectSize"></select>
<input type="button" value="" id="btnSetting" class="sysbtn" disabled="disabled">
<input type="button" value="" id="btnsetFormat" class="sysbtn" disabled="disabled">
</div>
<div>
<input type="button" value="" id="btnStart" start="false" class="sysbtn">
<input type="button" value="" id="btnCapture" class="sysbtn5" disabled="disabled">
</div>
<div class="buttons">
	<hr size="1" color="#B3AC9D">
	<script language="javascript" type="text/javascript">
		PrintButtons2();
	</script>
</div>

</body>

</html>
